#pragma once
#include "RenderTech.h"
#include "../Utility/DirectoryUtil.h"
#include "../IO/XYZFileIO.h"
#include "RenderColorBar.h"
#include "../MFCD3D11Test.h"
class CRenderHeightMap: public RenderTech
{
public:
	CRenderHeightMap(void);
	virtual ~CRenderHeightMap(void);
	HRESULT PreparedXYZRenderBufs(ID3D11Device* pd3dDevice);
	//D3D series functions
	virtual HRESULT OnD3D11CreateDevice( ID3D11Device* pd3dDevice, CDirectoryUtil* pDirUtil, void* pUserContext );
	virtual HRESULT OnD3D11ResizedSwapChain( ID3D11Device* pd3dDevice, IDXGISwapChain* pSwapChain,
                                         const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, CDirectoryUtil* pDirUtil, void* pUserContext );
	virtual void OnD3D11ReleasingSwapChain( void* pUserContext );
	virtual void OnD3D11DestroyDevice( void* pUserContext );
	virtual void OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, CBaseCamera* pViewCamera, CDirectoryUtil* pDirUtil, double fTime,
                                 float fElapsedTime, void* pUserContext );
	virtual void InitEffectsVariables();
	virtual void ReloadEffectsDebug(ID3D11Device* pd3dDevice, CDirectoryUtil* pDirUtil);
	HRESULT prepareNormalLineVB(ID3D11Device* pd3dDevice);
	void RenderNormalLines(ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, CBaseCamera* pViewCamera, CDirectoryUtil* pDirUtil, double fTime,
		float fElapsedTime, NORMALESTIMATEMETHOD iCurNormalMethod, void* pUserContext);
	inline CXYZFileIO* GetCurXYZFile() {return m_pXYZFile;}
	void SetXYZFilePointer(CXYZFileIO* pXYZFile);
	inline D3DXVECTOR4 GetNormalLineColor() {return m_vNormalLineColor;}
	inline void SetNormalLineColor(const D3DXVECTOR4 vColor){m_vNormalLineColor=vColor;}
	inline int GetNormalWndSize() {return m_pXYZFile->GetNormalWndSize();}
	HRESULT SetNormalWndSize(ID3D11Device* pd3dDevice, int iSize);
	inline float GetNFGaussianSigma() {return m_pXYZFile->GetGaussianSigma();};
	HRESULT SetNFGaussianSigma(ID3D11Device* pd3dDevice, float fNewSigma);
	float GetNormalLineScale() {return m_fNormalLineScale;}
	HRESULT SetNormalLineScale(ID3D11Device* pd3dDevice, float fScale);
	inline bool GetbRenderNormal() {return m_bRenderNormal;}
	inline void SetbRenderNormal(bool bRender) {m_bRenderNormal=bRender;}
	inline bool GetbRenderWF() {return m_bRenderWireFrame;}
	inline void SetbRenderWF(bool bWF) {m_bRenderWireFrame = bWF;}
	inline bool GetDataStatus() {return m_bDataReady;}
	inline void SetDataStatus(bool bReady) {m_bDataReady = bReady;}
private:
	CXYZFileIO* m_pXYZFile;
	bool        m_bDataReady;
	//D3D series members
	ID3D11Buffer*				m_pVB;
	ID3D11Buffer*               m_pIB;
	ID3D11Buffer*               m_pNormalLineVB;
	int m_iNumOfNormLine;
	//Effect variables
	ID3DX11EffectTechnique*              m_pRenderHeightMapTech;
	ID3DX11EffectTechnique*				 m_pRenderHeightMapWFTech;
	ID3DX11EffectTechnique*              m_pRenderHeightMapNormalTech;
	ID3DX11EffectMatrixVariable*         m_pWorldViewProjection;
	ID3DX11EffectScalarVariable*         m_pHeightRange;
	ID3DX11EffectVectorVariable*         m_pNormalDebugColor;
	ID3DX11EffectShaderResourceVariable* m_pColorBarTex;
	ID3D11InputLayout*                   m_pVertexLayout;
	
	//assist
	CRenderColorBar*  m_pColorBar;
	D3DXVECTOR4  m_vNormalLineColor;
	float	m_fNormalLineScale;
	bool m_bRenderNormal;
	bool m_bRenderWireFrame;
	//scaling matrix
	D3DXMATRIX    m_matScaling;

};

